﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using ChuanYe.Core.Utils;
using ChuanYe.CountyFireManagement.Api.Models;
using ChuanYe.CountyFireManagement.BLL;
using ChuanYe.CountyFireManagement.EF.MySQL.Models;
using ChuanYe.CountyFireManagement.Model;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace ChuanYe.CountyFireManagement.Api.Controllers
{
    /// <summary>
    /// 提供基础数据管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class BasicDataController : ControllerBase
    {
        #region Power

        /// <summary>
        ///  增加权限明细
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ResultDtoBase AddPower(PowerRequest obj)
        {
            ResultDtoBase result = new ResultDtoBase();
            try
            {
                Power info = new Power();
                info.PowerKey = obj.PowerKey;
                info.PowerName = obj.PowerName;
                info.ShowName = obj.ShowName ?? obj.PowerName;
                info.Sort = obj.Sort;
                info.ParentId = obj.ParentId;
                result.Status  = UserBLL.Instance.AddPower(info);
                if (result.Status == -2)
                {
                    result.Status = -2;
                    result.Message = "Name Is Exist";
                }
            }
            catch (Exception ex)
            {
                result.Status = 500;
                result.Message = "/BasicData/AddPower Server Error";
                LogHelper.Error(result.Message,ex);
            }
            return result;
        }

        /// <summary>
        ///  获取权限明细
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ResultDto<List<Power>> GetPower()
        {
            ResultDto<List<Power>> result = new ResultDto<List<Power>>();
            try
            {
                result.FirstParam = UserBLL.Instance.GetPower();
            }
            catch (Exception ex)
            {
                result.Status = 500;
                result.Message = "/BasicData/GetPower Server Error";
                LogHelper.Error(result.Message,ex);
            }
            return result;
        }

        /// <summary>
        ///  获取权限明细 分页
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ResultDto<dynamic, dynamic> GetPowerByPage(PowerSearchRequest obj)
        {
            ResultDto<dynamic, dynamic> result = new ResultDto<dynamic, dynamic>();
            try
            {
                var page = Pickout.SetPage(obj);
                return UserBLL.Instance.GetPowerByPage(obj.PowerKey,obj.PowerName, page);
            }
            catch (Exception ex)
            {
                result.Status = 500;
                result.Message = "/BasicData/GetPowerByPage Server Error";
                LogHelper.Error(result.Message,ex);
            }
            return result;
        }

        /// <summary>
        ///  删除权限明细
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ResultDtoBase RemovePower(RemovePowerRequest obj)
        {
            ResultDtoBase result = new ResultDtoBase();
            try
            {
                result.Status= UserBLL.Instance.RemovePower(obj.PowerId);
                if (result.Status == -1)
                {
                    result.Message = "Power Is Not Exist";
                }
                if (result.Status == -2)
                {
                    result.Message = "Rolepower Is Exist";
                }
            }
            catch (Exception ex)
            {
                result.Status = 500;
                result.Message = "/BasicData/RemovePower Server Error";
                LogHelper.Error(result.Message,ex);
            }
            return result;
        }

        /// <summary>
        ///  更改权限明细
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ResultDtoBase UpdatePower(PowerRequest obj)
        {
            ResultDtoBase result = new ResultDtoBase();
            try
            {
                Power info = new Power();
                info.PowerId = obj.PowerId;
                info.PowerKey = obj.PowerKey;
                info.PowerName = obj.PowerName;
                info.ShowName = obj.ShowName ?? obj.PowerName;
                info.Sort = obj.Sort;
                info.ParentId = obj.ParentId;
                result.Status = UserBLL.Instance.UpdatePower(info);
                if (result.Status == -2)
                {
                    result.Message = "Name Is Exist";
                }
            }
            catch (Exception ex)
            {
                result.Status = 500;
                result.Message = "/BasicData/UpdatePower Server Error";
                LogHelper.Error(result.Message,ex);
            }
            return result;
        }
        #endregion

        #region Role

        /// <summary>
        ///  增加权限
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ResultDtoBase AddRole(RoleRequest obj)
        {
            ResultDtoBase result = new ResultDtoBase();
            try
            {
                Role info = new Role();
                info.RoleName = obj.RoleName;
                info.Description = obj.Description;
                info.Enabled = obj.Enabled.HasValue ==false ?1: obj.Enabled.Value;
                info.RoleLevelId = obj.RoleLevelId;
                result.Status = UserBLL.Instance.AddRole(info);
                if (result.Status == -2)
                {
                    result.Message = "Name Is Exist";
                }
            }
            catch (Exception ex)
            {
                result.Status = 500;
                result.Message = "/BasicData/AddRole Server Error";
                LogHelper.Error(result.Message,ex);
            }
            return result;
        }


        /// <summary>
        ///  获取权限
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ResultDto<List<Role>> GetRole()
        {
            ResultDto<List<Role>> result = new ResultDto<List<Role>>();
            try
            {
                result.FirstParam = UserBLL.Instance.GetRole();
            }
            catch (Exception ex)
            {
                result.Status = 500;
                result.Message = "/BasicData/Role Server Error";
                LogHelper.Error(result.Message,ex);
            }
            return result;
        }

        /// <summary>
        ///  获取权限 分页
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ResultDto<dynamic, dynamic> GetRoleByPage(RoleSearchRequest obj)
        {
            ResultDto<dynamic, dynamic> result = new ResultDto<dynamic, dynamic>();
            try
            {
                var page = Pickout.SetPage(obj);
                return UserBLL.Instance.GetRoleByPage(obj.RoleName, page);
            }
            catch (Exception ex)
            {
                result.Status = 500;
                result.Message = "/BasicData/GetRoleByPage Server Error";
                LogHelper.Error(result.Message,ex);
            }
            return result;
        }

        /// <summary>
        ///  删除权限
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ResultDtoBase RemoveRole(RemoveRoleRequest obj)
        {
            ResultDtoBase result = new ResultDtoBase();
            try
            {
                result.Status = UserBLL.Instance.RemoveRole(obj.RoleId);

                if (result.Status == -1)
                {
                    result.Message = "Role Is Not Exist";
                }
                if (result.Status == -2)
                {
                    result.Message = "Userinfo Already Occupied";
                }
                if (result.Status == -3)
                {
                    result.Message = "Name Is Exist";
                }
            }
            catch (Exception ex)
            {
                result.Status = 500;
                result.Message = "/BasicData/RemoveRole Server Error";
                LogHelper.Error(result.Message,ex);
            }
            return result;
        }


        /// <summary>
        ///  更改权限
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ResultDtoBase UpdateRole(RoleRequest obj)
        {
            ResultDtoBase result = new ResultDtoBase();
            try
            {
                Role info = new Role();
                info.RoleId = obj.RoleId;
                info.RoleName = obj.RoleName;
                info.Description = obj.Description;
                info.Enabled = obj.Enabled.HasValue ?  obj.Enabled.Value:1;
                info.RoleLevelId = obj.RoleLevelId;
                result.Status = UserBLL.Instance.UpdateRole(info);
                if (result.Status == -1)
                {
                    result.Message = "Role Is Not Exist";
                }
                if (result.Status == -2)
                {
                    result.Message = "Role Is Exist";
                }
            }
            catch (Exception ex)
            {
                result.Status = 500;
                result.Message = "/BasicData/UpdateRole Server Error";
                LogHelper.Error(result.Message,ex);
            }
            return result;
        }

        #endregion

        #region RolePower

        /// <summary>
        ///  增加权限关系
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ResultDtoBase AddRolePower(RolePowerRequest obj)
        {
            ResultDtoBase result = new ResultDtoBase();
            try
            {
                Rolepower info = new Rolepower();
                info.RoleId = obj.RoleId;
                info.PowerId = obj.PowerId;
                info.CreateTime = obj.CreateTime.HasValue ? DateTime.Now : obj.CreateTime.Value;
                result.Status = UserBLL.Instance.AddRolePower(info);
                if (result.Status == -2)
                {
                    result.Message = "RolePower Is Exist";
                }
            }
            catch (Exception ex)
            {
                result.Status = 500;
                result.Message = "/BasicData/AddRolePower Server Error";
                LogHelper.Error(result.Message,ex);
            }
            return result;
        }

        /// <summary>
        ///  获取权限关系
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ResultDto<List<dynamic>> GetRolePower(RolePowerSearchRequest obj)
        {
            ResultDto<List<dynamic>> result = new ResultDto<List<dynamic>>();
            try
            {
                result.FirstParam = UserBLL.Instance.GetRolePower(obj.RoleId);
            }
            catch (Exception ex)
            {
                result.Status = 500;
                result.Message = "/BasicData/GetRolePower Server Error";
                LogHelper.Error(result.Message,ex);
            }
            return result;
        }
        
        /// <summary>
        ///  获取权限关系 分页
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ResultDto<dynamic, dynamic> GetRolePowerByPage(RolePowerSearchRequest2 obj)
        {
            ResultDto<dynamic, dynamic> result = new ResultDto<dynamic, dynamic>();
            try
            {
                var page = Pickout.SetPage(obj);
                return UserBLL.Instance.GetRolePowerByPage(page);
            }
            catch (Exception ex)
            {
                result.Status = 500;
                result.Message = "/BasicData/GetRolePowerByPage Server Error";
                LogHelper.Error(result.Message,ex);
            }
            return result;
        }

        /// <summary>
        ///  删除权限关系
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ResultDtoBase RemoveRolePower(RemoveRolePowerRequest obj)
        {
            ResultDtoBase result = new ResultDtoBase();
            try
            {
                result.Status = UserBLL.Instance.RemoveRolePower(obj.RolePowerId);
                if (result.Status == -1)
                {
                    result.Message = "RolePower Is Not Exist";
                }
            }
            catch (Exception ex)
            {
                result.Status = 500;
                result.Message = "/BasicData/RemoveRolePower Server Error";
                LogHelper.Error(result.Message,ex);
            }
            return result;
        }

        /// <summary>
        ///  更改权限关系
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ResultDtoBase UpdateRolePower(RolePowerRequest obj)
        {
            ResultDtoBase result = new ResultDtoBase();
            try
            {
                Rolepower info = new Rolepower();
                info.RolePowerId = obj.RolePowerId;
                info.RoleId = obj.RoleId;
                info.PowerId = obj.PowerId;
                info.CreateTime = obj.CreateTime.HasValue ? DateTime.Now : obj.CreateTime.Value;
                result.Status = UserBLL.Instance.UpdateRolePower(info);
                if (result.Status == -1)
                {
                    result.Message = "RolePower Is Not Exist";
                }
                if (result.Status == -2)
                {
                    result.Message = "Name Is Exist ";
                }
            }
            catch (Exception ex)
            {
                result.Status = 500;
                result.Message = "/BasicData/UpdateRolePower Server Error";
                LogHelper.Error(result.Message,ex);
            }
            return result;
        }

        #endregion

        #region Department
        /// <summary>
        ///  获取部门
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ResultDto<List<Department>> GetDepartment()
        {
            ResultDto<List<Department>> result = new ResultDto<List<Department>>();
            try
            {
                result.FirstParam = UserBLL.Instance.GetDepartment();
            }
            catch (Exception ex)
            {
                result.Status = 500;
                result.Message = "/BasicData/GetDepartment Server Error";
                LogHelper.Error(result.Message,ex);
            }
            return result;
        }

        /// <summary>
        ///   移除部门
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ResultDtoBase RemoveDepartment(RemoveDepartmentRequest obj)
        {
            ResultDtoBase result = new ResultDtoBase();
            try
            {
                result.Status  = UserBLL.Instance.RemoveDepartment(obj.DepId);
                if (result.Status == -1)
                {
                    result.Message = "Department Is  Exist";
                }
            }
            catch (Exception ex)
            {
                result.Status = 500;
                result.Message = "/BasicData/RemoveDepartment Server Error";
                LogHelper.Error(result.Message,ex);
            }
            return result;
        }

        /// <summary>
        ///  增加部门
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ResultDtoBase AddDepartment(DepartmentRequest obj)
        {
            ResultDtoBase result = new ResultDtoBase();
            try
            {
                Department info = new Department();
                info.DepName = obj.DepName;
                info.Sort = obj.Sort;
                info.Remarks = obj.Remarks;
                result.Status = UserBLL.Instance.AddDepartment(info);
                if (result.Status == -1)
                {
                    result.Message = "Name Is Exist";
                }
            }
            catch (Exception ex)
            {
                result.Status = 500;
                result.Message = "/BasicData/AddDepartment Server Error";
                LogHelper.Error(result.Message,ex);
            }
            return result;
        }


        /// <summary>
        ///  更改部门
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ResultDtoBase UpdateDepartment(DepartmentRequest obj)
        {
            ResultDtoBase result = new ResultDtoBase();
            try
            {
                Department info = new Department();
                info.DepId = obj.DepId;
                info.DepName = obj.DepName;
                info.Sort = obj.Sort;
                info.Remarks = obj.Remarks;
                result.Status = UserBLL.Instance.UpdateDepartment(info);

                if (result.Status == -1)
                {
                    result.Message = "Department Is Not Exist";
                }
                if (result.Status == -2)
                {
                    result.Message = "Name Is Exist";
                }
            }
            catch (Exception ex)
            {
                result.Status = 500;
                result.Message = "/BasicData/UpdateDepartment Server Error";
                LogHelper.Error(result.Message,ex);
            }
            return result;
        }



        /// <summary>
        ///  获取部门 分页
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ResultDto<dynamic, dynamic> GetDepartmentByPage(DepartmentSearchRequest obj)
        {
            ResultDto<dynamic, dynamic> result = new ResultDto<dynamic, dynamic>();
            try
            {
                var page = Pickout.SetPage(obj);
                return UserBLL.Instance.GetDepartmentByPage(page);
            }
            catch (Exception ex)
            {
                result.Status = 500;
                result.Message = "/BasicData/GetDepartmentByPage Server Error";
                LogHelper.Error(result.Message,ex);
            }
            return result;
        }

        #endregion

        #region Position

        /// <summary>
        ///  获取职务
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ResultDto<List<Position>> GetPosition()
        {
            ResultDto<List<Position>> result = new ResultDto<List<Position>>();
            try
            {
                result.FirstParam = UserBLL.Instance.GetPosition();
            }
            catch (Exception ex)
            {
                result.Status = 500;
                result.Message = "/BasicData/GetGetPosition Server Error";
                LogHelper.Error(result.Message,ex);
            }
            return result;
        }

        /// <summary>
        ///  移除职务
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ResultDtoBase RemovePosition(RemovePositionRequest obj)
        {
            ResultDtoBase result = new ResultDtoBase();
            try
            {
                result.Status = UserBLL.Instance.RemovePosition(obj.PositionId);
                if (result.Status == -2)
                {
                    result.Message = "Name Is Exist";
                }
            }
            catch (Exception ex)
            {
                result.Status = 500;
                result.Message = "/BasicData/RemovePosition Server Error";
                LogHelper.Error(result.Message,ex);
            }
            return result;
        }

        /// <summary>
        ///  增加职务
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ResultDtoBase AddPosition(PositionRequest obj)
        {
            ResultDtoBase result = new ResultDtoBase();
            try
            {
                Position info = new Position();
                info.PositionName = obj.PositionName;
                info.Sort = obj.Sort;
                result.Status = UserBLL.Instance.AddPosition(info);
                if (result.Status == -2)
                {
                    result.Message = "Name Is Exist";
                }
            }
            catch (Exception ex)
            {
                result.Status = 500;
                result.Message = "/BasicData/AddDepartment Server Error";
                LogHelper.Error(result.Message,ex);
            }
            return result;
        }

        /// <summary>
        ///  编辑职务
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ResultDtoBase UpdatePosition(PositionRequest obj)
        {
            ResultDtoBase result = new ResultDtoBase();
            try
            {
                Position info = new Position();
                info.PositionId = obj.PositionId;
                info.PositionName = obj.PositionName;
                info.Sort = obj.Sort;
                result.Status = UserBLL.Instance.UpdatePosition(info);
                if (result.Status == -1)
                {
                    result.Message = "Position Is Exist ";
                }
                if (result.Status == -2)
                {
                    result.Message = "Name Is Exist";
                }
            }
            catch (Exception ex)
            {
                result.Status = 500;
                result.Message = "/BasicData/UpdatePosition Server Error";
                LogHelper.Error(result.Message,ex);
            }
            return result;
        }

        /// <summary>
        ///  获取职务 分页
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ResultDto<dynamic, dynamic> GetPositionByPage(PositionSearchRequest obj)
        {
            ResultDto<dynamic, dynamic> result = new ResultDto<dynamic, dynamic>();
            try
            {
                var page = Pickout.SetPage(obj);
                return UserBLL.Instance.GetPositionByPage(page);
            }
            catch (Exception ex)
            {
                result.Status = 500;
                result.Message = "/BasicData/GetPositionByPage Server Error";
                LogHelper.Error(result.Message,ex);
            }
            return result;
        }

        #endregion

        #region FireHeadquarter

        /// <summary>
        /// 增加指挥部
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        [HttpPost]
        public ResultDtoBase AddFireHeadquarter(FireheadquarterRequest obj)
        {
            ResultDtoBase result = new ResultDtoBase();
            try
            {
                string ip = HttpContext.GetClientIp();
                Fireheadquarter info = new Fireheadquarter();
                info.Name = obj.Name;
                info.ParentId = obj.ParentId;
                info.Sort = obj.Sort;
                info.Tel = obj.Tel;
                info.Ip = ip;
                info.AddressCounty = obj.AddressCounty;
                info.AddressTown = obj.AddressTown;
                info.AddressVillage = obj.AddressVillage;
                info.TransDatetime = obj.TransDatetime.HasValue ? obj.TransDatetime.Value : DateTime.Now;
                result.Status = BLL.FireHeadquarterBLL.Instance.Add(info);
                if (result.Status == -2)
                {
                    result.Message = "Name Is Exist";
                }
            }
            catch (Exception ex)
            {
                result.Status = 500;
                result.Message = "/BasicData/AddFireHeadquarter Server Error";
                LogHelper.Error(result.Message,ex);
            }
            return result;
        }


        /// <summary>
        /// 获取指挥部
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        [HttpPost]
        public ResultDto<dynamic> GetFireHeadquarter(FireHeadquarterSearchRequest obj)
        {
            ResultDto<dynamic> result = new ResultDto<dynamic>();
            try
            {
                result.FirstParam = BLL.FireHeadquarterBLL.Instance.Get(obj.AddressCounty, obj.AddressTown, obj.AddressVillage);
            }
            catch (Exception ex)
            {
                result.Status = 500;
                result.Message = "/BasicData/GetFireHeadquarter Server Error";
                LogHelper.Error(result.Message,ex);
            }
            return result;
        }

        /// <summary>
        /// 获取指挥部 分页
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        [HttpPost]
        public ResultDto<dynamic, dynamic> GetFireHeadquarterByPage(FireHeadquarterSearchRequest2 obj)
        {
            ResultDto<dynamic, dynamic> result = new ResultDto<dynamic, dynamic>();
            try
            {
                var page = Pickout.SetPage(obj);
                return BLL.FireHeadquarterBLL.Instance.GetByPage(obj.AddressCounty, obj.AddressTown, obj.AddressVillage,page);
            }
            catch (Exception ex)
            {
                result.Status = 500;
                result.Message = "/BasicData/GetFireHeadquarterByPage Server Error";
                LogHelper.Error(result.Message,ex);
            }
            return result;
        }


        /// <summary>
        ///  编辑指挥部
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ResultDtoBase UpdateFireHeadquarter(FireheadquarterRequest obj)
        {
            ResultDtoBase result = new ResultDtoBase();
            try
            {
                string ip = HttpContext.GetClientIp();
                Fireheadquarter info = new Fireheadquarter();
                info.HeadquarterId = obj.HeadquarterId;
                info.Name = obj.Name;
                info.ParentId = obj.ParentId;
                info.Sort = obj.Sort;
                info.Tel = obj.Tel;
                info.Ip = ip;
                info.AddressCounty = obj.AddressCounty;
                info.AddressTown = obj.AddressTown;
                info.AddressVillage = obj.AddressVillage;
                info.TransDatetime = obj.TransDatetime.HasValue ? obj.TransDatetime.Value : DateTime.Now;
                result.Status  = BLL.FireHeadquarterBLL.Instance.Update(info);
                if (result.Status == -1)
                {
                    result.Message = "FireHeadquarter Is Not Exist";
                }
                if (result.Status == -2)
                {
                    result.Message = "Name Is Exist";
                }
            }
            catch (Exception ex)
            {
                result.Status = 500;
                result.Message = "/BasicData/UpdateFireHeadquarter Server Error";
                LogHelper.Error(result.Message,ex);
            }
            return result;
        }



        /// <summary>
        ///  移除指挥部
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ResultDtoBase RemoveFireHeadquarter(RemoveFireheadquarterRequest obj)
        {
            ResultDtoBase result = new ResultDtoBase();
            try
            {
                result.Status = BLL.FireHeadquarterBLL.Instance.Remove(obj.HeadquarterId);
                if (result.Status == -1)
                {
                    result.Message = "FireHeadquarter Is Not Exist ";
                }
                if (result.Status == -2)
                {
                    result.Message = "FireFightingForce Already Occupied";
                }
                if (result.Status == -3)
                {
                    result.Message = "FireHeadquarterMember Already Occupied";
                }
            }
            catch (Exception ex)
            {
                result.Status = 500;
                result.Message = "/BasicData/RemoveFireHeadquarter Server Error";
                LogHelper.Error(result.Message,ex);
            }
            return result;
        }


        #endregion

        #region HeadquarterMember
        /// <summary>
        /// 增加指挥部人员
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        [HttpPost]
        public ResultDtoBase AddFireHeadquarterMember(FireheadquarterMemberRequest obj)
        {
            ResultDtoBase result = new ResultDtoBase();
            try
            {
                string ip = HttpContext.GetClientIp();
                Fireheadquartermember info = new Fireheadquartermember();
                info.HeadquarterId = obj.HeadquarterId;
                info.TeamDepartmentId = obj.TeamDepartmentId;
                info.Tel = obj.Tel;
                info.Name = obj.Name;
                info.PositionId = obj.PositionId;
                info.TransDatetime = obj.TransDatetime.HasValue ? obj.TransDatetime.Value : DateTime.Now;
                info.Phone = obj.Phone;
                result.Status  = BLL.FireHeadquarterMemberBLL.Instance.Add(info);
                if (result.Status == -2)
                {
                    result.Message = "Name Is Exist";
                }
            }
            catch (Exception ex)
            {
                result.Status = 500;
                result.Message = "/BasicData/AddFireHeadquarterMember Server Error";
                LogHelper.Error(result.Message,ex);
            }
            return result;
        }

        /// <summary>
        /// 获取指挥部人员
        /// </summary>
        /// <param name="obj">obj.FireId</param>
        /// <returns></returns>
        [HttpPost]
        public ResultDto<dynamic> GetFireHeadquarterMember(FireHeadquarterMemberSearchRequest obj)
        {
            ResultDto<dynamic> result = new ResultDto<dynamic>();
            try
            {
                result.FirstParam = BLL.FireHeadquarterMemberBLL.Instance.Get(obj.HeadquarterId);
            }
            catch (Exception ex)
            {
                result.Status = 500;
                result.Message = "/BasicData/GetFireHeadquarterMember Server Error";
                LogHelper.Error(result.Message,ex);
            }
            return result;
        }

        /// <summary>
        /// 获取指挥部人员 分页
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        [HttpPost]
        public ResultDto<dynamic, dynamic> GetFireHeadquarterMemberByPage(FireHeadquarterMemberSearchRequest2 obj)
        {
            ResultDto<dynamic, dynamic> result = new ResultDto<dynamic, dynamic>();
            try
            {
                var page = Pickout.SetPage(obj);
                return BLL.FireHeadquarterMemberBLL.Instance.GetByPage(page);
            }
            catch (Exception ex)
            {
                result.Status = 500;
                result.Message = "/BasicData/GetFireHeadquarterMemberByPage Server Error";
                LogHelper.Error(result.Message,ex);
            }
            return result;
        }

        /// <summary>
        ///  编辑指挥部人员
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ResultDtoBase UpdateFireHeadquarterMember(FireheadquarterMemberRequest obj)
        {
            ResultDtoBase result = new ResultDtoBase();
            try
            {
                string ip = HttpContext.GetClientIp();
                Fireheadquartermember info = new Fireheadquartermember();
                info.HeadquarterMemberId = obj.HeadquarterMemberId;
                info.HeadquarterId = obj.HeadquarterId;
                info.TeamDepartmentId = obj.TeamDepartmentId;
                info.Tel = obj.Tel;
                info.Name = obj.Name;
                info.PositionId = obj.PositionId;
                info.TransDatetime = obj.TransDatetime.HasValue ? obj.TransDatetime.Value : DateTime.Now;
                info.Phone = obj.Phone;
                result.Status = BLL.FireHeadquarterMemberBLL.Instance.Update(info);
                if (result.Status == -1)
                {
                    result.Message = "Fireheadquartermember Is Not Exist";
                }
            }
            catch (Exception ex)
            {
                result.Status = 500;
                result.Message = "/BasicData/UpdateFireHeadquarterMember Server Error";
                LogHelper.Error(result.Message,ex);
            }
            return result;
        }

        /// <summary>
        ///  移除编辑指挥部人员
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ResultDtoBase RemoveFireHeadquarterMember(RemoveFireheadquarterMemberRequest obj)
        {
            ResultDtoBase result = new ResultDtoBase();
            try
            {
                result.Status = BLL.FireHeadquarterMemberBLL.Instance.Remove(obj.HeadquarterMemberId);
                if (result.Status == -1)
                {
                    result.Message = "Fireheadquartermember Is Not Exist";
                }
                if (result.Status == -2)
                {
                    result.Message = "Firefrontcommand Already Occupied";
                }
            }
            catch (Exception ex)
            {
                result.Status = 500;
                result.Message = "/BasicData/RemoveFireHeadquarterMember Server Error";
                LogHelper.Error(result.Message,ex);
            }
            return result;
        }

        #endregion

        #region  TeamDepartment
        /// <summary>
        ///  获取联动响应 单位
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ResultDto<dynamic> GetTeamDepartment()
        {
            ResultDto<dynamic> result = new ResultDto<dynamic>();
            try
            {
                result.FirstParam = BLL.FireTeamResponseBLL.Instance.GetTeamDepartment(0, false);
            }
            catch (Exception ex)
            {
                result.Status = 500;
                result.Message = "/BasicData/GetTeamDepartment Server Error";
                LogHelper.Error(result.Message,ex);
            }
            return result;
        }


        /// <summary>
        ///  增加联动响应单位
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        [HttpPost]
        public ResultDtoBase AddTeamDepartment(TeamDepartmentRequest obj)
        {
            ResultDtoBase result = new ResultDtoBase();
            try
            {
                Fireteamdepartment info = new Fireteamdepartment()
                {
                    Name = obj.Name,
                    Ip = HttpContext.GetClientIp(),
                    Phone = obj.Phone,
                    Remarks = obj.Remarks,
                    Sort = obj.Sort,
                    Tel = obj.Tel,
                    UserId = obj.UserId,
                    TransDatetime = obj.TransDatetime.HasValue ? obj.TransDatetime.Value : DateTime.Now,
                };
                result.Status  = BLL.FireTeamResponseBLL.Instance.AddTeamDepartment(info);
                if (result.Status == -2)
                {
                    result.Status = -2;
                    result.Message = " Name Is Exist ";
                }
            }
            catch (Exception ex)
            {
                result.Status = 500;
                result.Message = "/BasicData/AddTeamDepartment Server Error";
                LogHelper.Error(result.Message,ex);
            }
            return result;
        }

        /// <summary>
        ///  编辑联动响应单位
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ResultDtoBase UpdateTeamDepartment(TeamDepartmentRequest obj)
        {
            ResultDtoBase result = new ResultDtoBase();
            try
            {
                Fireteamdepartment info = new Fireteamdepartment()
                {
                    TeamDepartmentId=obj.TeamDepartmentId,
                    Name = obj.Name,
                    Ip = HttpContext.GetClientIp(),
                    Phone = obj.Phone,
                    Remarks = obj.Remarks,
                    Sort = obj.Sort,
                    Tel = obj.Tel,
                    UserId = obj.UserId,
                    TransDatetime = obj.TransDatetime.HasValue ? obj.TransDatetime.Value : DateTime.Now,
                };
                result.Status  = BLL.FireTeamResponseBLL.Instance.UpdateTeamDepartment(info);
                if (result.Status == -2)
                {
                    result.Status = -2;
                    result.Message = " Name Is Exist ";
                }
            }
            catch (Exception ex)
            {
                result.Status = 500;
                result.Message = "/BasicData/UpdateTeamDepartment Server Error";
                LogHelper.Error(result.Message,ex);
            }
            return result;
        }


        /// <summary>
        /// 获取联动响应单位 分页
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        [HttpPost]
        public ResultDto<dynamic, dynamic> GetFireTeamDepartmentByPage(FireTeamDepartmentSearchRequest obj)
        {
            ResultDto<dynamic, dynamic> result = new ResultDto<dynamic, dynamic>();
            try
            {
                var page = Pickout.SetPage(obj);
                return BLL.FireTeamResponseBLL.Instance.GetFireTeamDepartmentByPage(page);
            }
            catch (Exception ex)
            {
                result.Status = 500;
                result.Message = "/BasicData/GetFireTeamDepartmentByPage Server Error";
                LogHelper.Error(result.Message,ex);
            }
            return result;
        }


        /// <summary>
        ///  删除联动响应单位
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        [HttpPost]
        public ResultDtoBase RemoveTeamDepartment(RemoveTeamDepartmentRequest obj)
        {
            ResultDtoBase result = new ResultDtoBase();
            try
            {
                result.Status = BLL.FireTeamResponseBLL.Instance.RemoveTeamDepartment(obj.TeamDepartmentId);
                if (result.Status == -1)
                {
                   
                    result.Message = "FireTeamResponse Is Not Exist";
                }
                if (result.Status == -2)
                {
                    result.Message = "Fireteamresponse Already Occupied";
                }
                if (result.Status == -3)
                {
                    result.Message = "FireHeadquartermember Already Occupied";
                }
            }
            catch (Exception ex)
            {
                result.Status = 500;
                result.Message = "/BasicData/RemoveTeamDepartment Server Error";
                LogHelper.Error(result.Message,ex);
            }
            return result;
        }




        #endregion

        #region User
        /// <summary>
        /// 增加用户
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        [HttpPost]
        public ResultDtoBase AddUser(UserRequest obj)
        {
            ResultDtoBase result = new ResultDtoBase();
            try
            {
                if (string.IsNullOrEmpty(obj.Password))
                {
                    obj.Password = "e10adc3949ba59abbe56e057f20f883e";
                    result.Message = "Add User Success,Default Password Code:123456";
                }
                Userinfo info = new Userinfo();
                info.AccountName = obj.AccountName;
                info.Password = obj.Password;
                info.Phone = obj.Phone;
                info.RealName = obj.RealName;
                info.DepId = obj.DepId;
                info.PositionId = obj.PositionId;
                info.RoleId = obj.RoleId;
                info.Sort = obj.Sort ?? 0;
                info.AddressCounty = obj.AddressCounty;
                info.AddressTown = obj.AddressTown;
                info.AddressVillage = obj.AddressVillage;
                info.CreateTime = obj.CreateTime ?? DateTime.Now;
                int userId=UserBLL.Instance.Add(info);
                result.Status  = userId;
                if (result.Status  == -2)
                {
                    result.Status = -2;
                    result.Message = " Name Is Exist ";
                }
            }
            catch (Exception ex)
            {
                result.Status = 500;
                result.Message = "/BasicData/AddUser Server Error";
                LogHelper.Error(result.Message,ex);
            }
            return result;
        }

        /// <summary>
        ///  编辑用户
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        [HttpPost]
        public ResultDtoBase UpdateUser(UserRequest obj)
        {
            ResultDtoBase result = new ResultDtoBase();
            try
            {
                if (!string.IsNullOrEmpty(obj.Password) && obj.Password.Length < 6)
                {
                    result.Status = 0;
                    result.Message = "Password Length Greater Than 6";
                }
                else
                {
                    Userinfo info = new Userinfo();
                    info.UserId = obj.UserId;
                    info.AccountName = obj.AccountName;
                    info.Password = obj.Password;
                    info.Phone = obj.Phone;
                    info.RealName = obj.RealName;
                    info.DepId = obj.DepId;
                    info.PositionId = obj.PositionId;
                    info.RoleId = obj.RoleId;
                    info.Sort = obj.Sort ?? 0;
                    info.AddressCounty = obj.AddressCounty;
                    info.AddressTown = obj.AddressTown;
                    info.AddressVillage = obj.AddressVillage;
                    info.CreateTime = obj.CreateTime ?? DateTime.Now;
                    UserBLL.Instance.Update(info);
                }
            }
            catch (Exception ex)
            {
                result.Status = 500;
                result.Message = "/BasicData/UpdateUser Server Error";
                LogHelper.Error(result.Message,ex);
            }
            return result;
        }

        /// <summary>
        /// 移除用户
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        [HttpPost]
        public ResultDtoBase RemoveUser(RemoveUserRequest obj)
        {
            ResultDtoBase result = new ResultDtoBase();
            try
            {
                string admin = AppSetting.GetConfig("Admin:AccountName");
                var request = HttpContext.Request;
                string accountName = request.Headers["AccountName"];
                if (string.IsNullOrEmpty(accountName))
                {
                    result.Status = 0;
                    result.Message = "Security Verification Is Null";
                    return result;
                }
                if (admin != accountName)
                {
                    result.Status = 0;
                    result.Message = "Security Verification Is Validation Failed";
                    return result;
                }
                result.Status  = UserBLL.Instance.Remove(obj.UserId);
                if (result.Status == -1)
                {
                    result.Status = -1;
                    result.Message = "Userinfo Is Not Exist";
                }
            }
            catch (Exception ex)
            {
                result.Status = 500;
                result.Message = "/BasicData/RemovePower Server Error";
                LogHelper.Error(result.Message,ex);
            }
            return result;
        }


        /// <summary>
        ///  获取用户  分页
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        [HttpPost]
        public ResultDto<dynamic, dynamic> GetUserByPage(UserSearchRequest obj)
        {
            ResultDto<dynamic, dynamic> result = new ResultDto<dynamic, dynamic>();
            try
            {
                var page = Pickout.SetPage(obj);
                return BLL.UserBLL.Instance.GetUserByPage(obj.AddressCounty, obj.AddressTown, obj.AddressVillage,page);
            }
            catch (Exception ex)
            {
                result.Status = 500;
                result.Message = "/BasicData/GetUserByPage Server Error";
                LogHelper.Error(result.Message,ex);
            }
            return result;
        }

        #endregion

        /// <summary>
        ///  获取权限级别
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ResultDto<dynamic> GetRoleLevel()
        {
            ResultDto<dynamic> result = new ResultDto<dynamic>();
            try
            {
                result.FirstParam = BLL.UserBLL.Instance.GetRoleLevel();
            }
            catch (Exception ex)
            {
                result.Status = 500;
                result.Message = "/BasicData/GetRoleLevel Server Error";
                LogHelper.Error(result.Message, ex);
            }
            return result;
        }




        /// <summary>
        /// 增加图层信息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ResultDtoBase AddMaplayer(MaplayerRequest obj)
        {
            ResultDtoBase result = new ResultDtoBase();
            try
            {
                Maplayer info = new Maplayer();
                info.LayerId = obj.LayerId;
                info.LayerName = obj.LayerName;
                info.LayerData = obj.LayerData;
                result.Status = MaplayerBLL.Instance.Add(info);

            }
            catch (Exception ex)
            {
                result.Status = 500;
                result.Message = "/BasicData/AddMaplayer Server Error";
                LogHelper.Error(result.Message, ex);
            }
            return result;
        }

        /// <summary>
        /// 移除图层信息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ResultDtoBase RemoveMaplayer(RemoveMaplayerRequest obj)
        {
            ResultDtoBase result = new ResultDtoBase();
            try
            {
                result.Status = MaplayerBLL.Instance.Remove(obj.LayerId);
                if (result.Status == -1)
                {
                    result.Message = "LayerId Is Not Exist";
                }
            }
            catch (Exception ex)
            {
                result.Status = 500;
                result.Message = "/BasicData/RemoveMaplayer Server Error";
                LogHelper.Error(result.Message, ex);
            }
            return result;
        }


        /// <summary>
        ///  编辑图层信息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ResultDtoBase UpdateMaplayer(MaplayerRequest obj)
        {
            ResultDtoBase result = new ResultDtoBase();
            try
            {
                Maplayer info = new Maplayer();
                info.LayerId = obj.LayerId;
                info.LayerName = obj.LayerName;
                info.LayerData = obj.LayerData;
                result.Status = MaplayerBLL.Instance.Update(info);

                if (result.Status == -1)
                {
                    result.Message = "LayerId Is Not Exist";
                }
            }
            catch (Exception ex)
            {
                result.Status = 500;
                result.Message = "/BasicData/UpdateMaplayer Server Error";
                LogHelper.Error(result.Message, ex);
            }
            return result;
        }


        /// <summary>
        ///  获取图层信息 分页
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ResultDto<dynamic, dynamic> GetMaplayerByPage(MaplayerSearchRequest obj)
        {
            ResultDto<dynamic, dynamic> result = new ResultDto<dynamic, dynamic>();
            try
            {
                var page = Pickout.SetPage(obj);
                return MaplayerBLL.Instance.GetByPage(page);
            }
            catch (Exception ex)
            {
                result.Status = 500;
                result.Message = "/BasicData/GetMaplayerByPage Server Error";
                LogHelper.Error(result.Message, ex);
            }
            return result;
        }








    }
}